/* */
import config from './config.js'
export default(url,data={},method="GET")=>{
    return new Promise((resolve,rejects)=>{
        //new Promise 初始化 promise 实例的状态 padding
        wx.request({
            url: config.host + url,
            data,
            method,
            header:{
                cookie : wx.getStorageSync('cookies')?wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U') !== -1):''
            },
            success: (res)=>{
                if (data.isLogin) {
                    wx.setStorage({
                        key: 'cookies',
                        data: res.cookies
                    })
                }
                resolve(res.data) //resolve 修改 promise 的状态为 resolved
            },
            fail: (err)=>{
                rejects(err) //reject 修改 promise 的状态为 rejected
            }
        })
    })
}